package www.configure.all.modules.controller;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import www.configure.all.modules.domain.R;
import www.configure.all.modules.websocket.StatusChangeWebsocketHandler;

@RestController
public class TwinBaseController {

    @Autowired
    private StatusChangeWebsocketHandler statusChangeWebsocketHandler;

    @GetMapping("/updateMaxLinkNum")
    public R updateClientNum (@RequestParam("maxNum") Integer maxNum , @RequestParam("serverIp") String serverIp){
        return statusChangeWebsocketHandler.updateServerLink(maxNum,serverIp);
    }

    /**
     * ue接口转发
     * @param input
     * @return
     */
    @PostMapping("/project/publish")
    public R ueForward (@RequestBody JSONObject input){
        System.out.println("进入接口："+input);
        return statusChangeWebsocketHandler.ueForward(input);
    }

    /**
     * 获取当前服务状态
     * @return
     */
    @GetMapping("/serverStatus")
    public R serverStatus (){
        return R.ok();
    }

    /**
     * UE启动成功 回调改变状态
     * @param port
     * @return
     */
    @GetMapping("/changeUeStatus")
    private R changeUeStatus(@RequestParam("port") String port){
        statusChangeWebsocketHandler.changeUeStatus(port);
        return R.ok();
    }

    /**
     * 获取当前缓存的信息
     * @return
     */
    @GetMapping("/getInfo")
    private R getInfo(){
        return R.ok(statusChangeWebsocketHandler.getInfo());
    }

    /**
     * 获取当前GPU信息
     * @return
     */
    @GetMapping("/getGpuStatus")
    private R getGpuStatus(){
        return R.ok(statusChangeWebsocketHandler.getGpuStatus());
    }
}
